﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using KMFrame.Permission.Util;
using LGCourt.Logic.NBL.DBEntities;

namespace lgweb.user
{
    public partial class judges : System.Web.UI.Page
    {
        private string _AH = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!SessionBox.CheckUserSession())
            {
                Response.Redirect("/user/login.aspx");
            }

            GetParam(); 
            if (!this.IsPostBack)
            {
                GetAHInfo();
                GetCaseALLInfo();
                GetDateWeek();
            }
        }

        private void GetParam()
        {
            this._AH = string.IsNullOrEmpty(Request.QueryString["ah"]) ? "" : Request.QueryString["ah"];
            if (string.IsNullOrEmpty(this._AH))
            {
                Response.Redirect("/user/index.aspx");
            }

            this.hdnAH.Value = this._AH;
            this.spAH.InnerHtml = this._AH;
        }

        /// <summary>
        /// 获取约见法官
        /// </summary>
        private void GetCaseALLInfo()
        {
            CaseInfo bll = new CaseInfo();

            int _userID = SessionBox.GetUserSession().UserID;
            UserCondition param = new UserCondition();
            param.AH = this._AH;
            param.UserID = _userID;

            CaseALLInfo result = bll.GetCaseALLInfo(param);

            if (result != null)
            {
                //当事人
                this.rptYYFGList.DataSource = result.YYFGList;
                this.rptYYFGList.DataBind();

            }
        }

        /// <summary>
        /// 获取案件信息
        /// </summary>
        private void GetAHInfo()
        {
            CaseInfo bll = new CaseInfo();

            int _userID = SessionBox.GetUserSession().UserID;
            UserCondition param = new UserCondition();
            param.AH = this._AH;
            param.UserID = _userID;

            CaseALLInfo result = (CaseALLInfo)bll.GetCaseALLInfo(param);

            if (result != null)
            {
                this.liAH.InnerHtml = this._AH;
                this.liCBR.InnerHtml = result.CBR;
            }
        }

        private void GetDateWeek()
        {
            CaseInfo bll = new CaseInfo();           

            List<DateWeek> result= bll.GetDateWeek();

            if (result != null)
            {
                //日期
                this.rptDateWeek.DataSource = result;
                this.rptDateWeek.DataBind();

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strSW = this.txtSW.Value;
            string strXW = this.txtXW.Value;

            bool sbool = false;

            //上午
            string[] aSWs = strSW.Split(',');
            for (int i = 0; i < aSWs.Length; i++)
            {
                CaseInfo blCaseInfol = new CaseInfo();

                pYYFG param = new pYYFG();
                param.YYR = SessionBox.GetUserSession().UserName;
                param.UserID = SessionBox.GetUserSession().UserID;
                param.FG = this.liCBR.InnerText;
                param.AH = this._AH;
                param.BZ = this.txtBZ.Value;
                param.YYSJ = DateTime.Parse(aSWs[i] + " 09:00:00");

                bool result = blCaseInfol.AddYYFG(param);

                if (result)
                {
                    sbool = true;
                }
            }

            //下午
            string[] aXWs = strXW.Split(',');
            for (int i = 0; i < aXWs.Length; i++)
            {
                CaseInfo blCaseInfol = new CaseInfo();

                pYYFG param = new pYYFG();
                param.YYR = SessionBox.GetUserSession().UserName;
                param.UserID = SessionBox.GetUserSession().UserID;
                param.FG = this.liCBR.InnerText;
                param.AH = this._AH;
                param.BZ = this.txtBZ.Value;
                param.YYSJ = DateTime.Parse(aXWs[i] + " 14:00:00");

                bool result = blCaseInfol.AddYYFG(param);

                if (result)
                {
                    sbool = true;
                }
            }

            if (sbool)
            {
                this.app_judges.Attributes.Add("class", "none");
                this.message_judges.Attributes.Add("class", "message");
                GetCaseALLInfo();
            }
        }

    }
}